package com.example.demo.chaincheck;

import org.springframework.util.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.BooleanSupplier;

/**
 * @author: twd
 * @since: 2023/7/14 14:35
 */
public class Checker {

    private Map<BooleanSupplier,String> q = new LinkedHashMap<>();

    public Checker add(BooleanSupplier e,String msg){
        q.put(e,msg);
        return this;
    }


    public String check(){
        for(Map.Entry<BooleanSupplier,String> e : q.entrySet() ){
            boolean asBoolean = e.getKey().getAsBoolean();
            if(!asBoolean){
                return e.getValue();
            }
        }
        return "";
    }

    public static void main(String[] args) {
        System.out.println(new Checker().add(() -> StringUtils.isEmpty(""),"1").add(() -> !StringUtils.isEmpty(""),"5").check());
        System.out.println(new Checker().add(() -> !StringUtils.isEmpty(""),"2").add(() -> StringUtils.isEmpty(""),"6").check());
        System.out.println(new Checker().add(() -> !StringUtils.isEmpty(""),"3").add(() -> !StringUtils.isEmpty(""),"7").check());
    }
}
